<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('服务商数据统计列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 80px;">日期：</label>
                                <input name="belong_date" type="text"  id="laydate-belong_date" placeholder="月份"/>
                            </li>
                            <li>
                                <label style="width: 80px;">服务商编号：</label>
                                <input name="agent_num" type="text"  id="agent_num" placeholder="服务商编号"/>
                            </li>
                            <li>
                                <label style="width: 80px;">服务商名称：</label>
                                <input name="agent_name" type="text"  id="agent_name" placeholder="服务商名称"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="exportActByMonthAndAgent()" shiro:hasPermission="agentDateCen:agentDateCen:exportActByMonthAndAgent">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-warning" onclick="exportDetail()" shiro:hasPermission="agentDateCen:agentDateCen:exportActByMonthAndAgent">
                    <i class="fa fa-download"></i> 导出明细
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "agentDateCen/agentDateCen";

        $(function() {
            var options = {
                url: prefix + "/activeMerByMonthAndAgent",
                exportUrl: prefix + "/export",
                modalName: "活跃商户按月数据统计",
                columns: [
                {
                    field: 'AGENT_NUM',
                    title: '服务商编号'
                },
                {
                    field: 'AGENT_NAME',
                    title: '服务商名称'
                },
                {
                    field: 'MER_ACTIVE_NUM',
                    title: '活跃商户数'
                },
                {
                    field: 'BELONG_DATE',
                    title: '月份'
                },]
            };
            $.table.init(options);
            layui.use('laydate', function() {
                var laydate = layui.laydate;
                laydate.render({
                    elem: '#laydate-belong_date',
                    type: 'month',
                    trigger: 'click'
                });
            });
        });
        function exportActByMonthAndAgent() {
            $.modal.loading("正在导出数据，请稍后...");
            $.post(prefix+"/exportActByMonthAndAgent", {"belong_date":$("#laydate-belong_date").val(),"agent_num":$("#agent_num").val(),"agent_name":$("#agent_name").val()},  function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        }

        function exportDetail() {
            var agent_num = $("input[name='agent_num']").val();
            var belongDate = $("input[name='belong_date']").val();
            if (agent_num.length == '0'){
                $.modal.alertWarning("请选择服务商")
                return;
            }
            $.modal.loading("正在导出数据，请稍后...");
            $.post(ctx + "merchantInfo/total/export", {"status":"1","agentNum":agent_num,"currentDateTime":belongDate}, function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        }

    </script>
</body>
</html>